package com.crm.controller.reportsController;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.crm.dao.OpportunityDAO;
import com.crm.entity.Business;
import com.crm.entity.Opportunity;

@Controller
@RequestMapping("/totalReports")
public class TotalReportsController {
	protected final Log logger = LogFactory.getLog(getClass());
	@RequestMapping( "/show.do") 
	public ModelAndView show(HttpServletRequest request,HttpSession session, ModelAndView model) throws Exception{
		System.out.println("We Are in total reports.do");
		Business bus=(Business)session.getAttribute("business");
		if(bus==null)return new ModelAndView("/jsp/index.jsp");
		System.out.println("After Checking business Session");
		//OpportunityDAO odao=new OpportunityDAO();
		List<Opportunity>  lop=null;
		try {
			lop=OpportunityDAO.getSingleInstance().getStatus(bus.getBusinessId());
		} catch(NullPointerException npe){
			logger.info("Null Pointer Exception Occured");
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		
		model.setViewName("/jsp/totalReports.jsp");
		model.addObject("opplist",lop);
		model.addObject("submenu", "reports");
		model.addObject("menuName","reports");
		System.out.println("End Of total reports controller");
		return model;
	}
}
